package com.zrrd.threadDaemon;
/**
 * @author WanJl
 * @version 1.0
 * @title MyThread
 * @description
 * @create 2024/6/16
 */
public class DaemonDemo {
    public static void main(String[] args) {
        MyThread1 myThread1 = new MyThread1();
        MyThread2 myThread2 = new MyThread2();
        myThread1.setName("线程1");
        myThread2.setName("线程2--守护线程");
        //setDaemon(boolean on) 设置此线程为守护线程
        //当普通线程结束的时候，守护线程也就没有继续运行下去的必要了
        myThread2.setDaemon(true);

        myThread1.start();
        myThread2.start();
    }
}
class MyThread1 extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(this.getName()+"-->"+i);
        }
    }
}
class MyThread2 extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(this.getName()+"-->"+i);
        }
    }
}

